import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { getDepartmentsByUnitCode } from '/@/api/system/system';
import { getModulesAll } from '/@/api/system/system';

export const columns: BasicColumn[] = [
  {
    title: '日期',
    dataIndex: 'logDate',
  },
  {
    title: '用户',
    dataIndex: 'realName',
  },
  {
    title: '部门',
    dataIndex: 'deptName',
  },
  {
    title: '动作',
    dataIndex: 'action',
    ellipsis: false,
  },
  {
    title: 'IP',
    dataIndex: 'ip',
  },
  {
    title: '设备',
    dataIndex: 'device',
  },
  {
    title: '类型',
    dataIndex: 'logTypeDesc',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'userName',
    label: '用户',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'device',
    label: '设备',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          value: '-1',
          label: '不限',
        },
        {
          value: '0',
          label: '电脑',
        },
        {
          value: '100',
          label: '手机',
        },
      ],
    },
  },
  {
    field: 'dates',
    label: '开始/结束时间',
    component: 'RangePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
      placeholder: ['开始时间', '结束时间'],
      showTime: false,
      style: 'width:100%',
      getPopupContainer: () => document.body,
    },
    colProps: { sm: 8, lg: 8, md: 8, xl: 8, xxl: 6 },
  },
  {
    field: 'userAction',
    label: '动作',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'deptCode',
    label: '部门',
    component: 'ApiTreeSelect',
    componentProps: {
      api: getDepartmentsByUnitCode,
      treeDefaultExpandAll: true,
      multiple: false,
      resultField: 'list',
      showSearch: true,
      treeNodeFilterProp: 'name',
      fieldNames: {
        label: 'name',
        key: 'code',
        value: 'code',
      },
      getPopupContainer: () => document.body,
    },
    colProps: { span: 6 },
  },
  {
    field: 'logType',
    label: '类别',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          value: '0',
          label: '登陆系统',
        },
        {
          value: '1',
          label: '退出登陆',
        },
        {
          value: '2',
          label: '操作',
        },
        {
          value: '3',
          label: '警告',
        },
        {
          value: '4',
          label: '出错',
        },
        {
          value: '5',
          label: '权限',
        },
        {
          value: '100',
          label: '攻击',
        },
      ],
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'byModuleCode',
    label: '基准模块',
    required: true,
    component: 'ApiSelect',
    colProps: { span: 22 },
    componentProps: {
      api: getModulesAll,
      labelField: 'name',
      valueField: 'code',
      showSearch: true,
      optionFilterProp: 'label',
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'f',
    label: ' ',
    component: 'Input',
    colProps: { span: 22 },
    render: () => {
      return '注意：同步后权限将与所选择的基准模块一致)';
    },
  },
];
